#include "gameselect.h"
#include<QDebug>
#include<fstream>
#include<iostream>
#include<QShortcut>
#include<QFormLayout>
#include<QButtonGroup>
#include<QLineEdit>
#include<QTimer>
#include<windows.h>
#include<QPushButton>
#include<QToolTip>
#include<QDockWidget>
#include<QDialog>
#include<QPushButton>
#include<QStatusBar>
#include<QToolBar>
#include<QMessageBox>
#include<QColorDialog>
#include<QFileDialog>
#include<QFontDialog>
#include<QTimer>
#include<QInputDialog>
#include<QFile>
#include<QFileDevice>
#include<QWaitCondition>
#include<Qpainter>
#include<QPaintEvent>
#include"gamehall.h"
#include"gamehome.h"

gameselect::gameselect(QWidget *parent) : QWidget(parent)
{
    QPushButton* back_button=new QPushButton(this);
    back_button->setGeometry(1460,1160,40,40);
    back_button->setIcon(QIcon(":res/back.png"));
    back_button->setIconSize(QSize(40,40));
    connect(back_button,&QPushButton::clicked,this,[=](){
        this->close();
        GameHall* gh=new GameHall;
        gh->show();
    });
    QPushButton* simple_button=new QPushButton(this);
    QPushButton* normal_button=new QPushButton(this);
    QPushButton* difficult_button=new QPushButton(this);
    QPushButton* history_button=new QPushButton(this);
    QFont font("微软雅黑",24);
    simple_button->setText("简单模式");
    normal_button->setText("正常模式");
    difficult_button->setText("困难模式");
    history_button->setText("历史战绩");
    simple_button->setFont(font);
    normal_button->setFont(font);
    difficult_button->setFont(font);
    history_button->setFont(font);

    simple_button->move(650,100);
    normal_button->move(650,300);
    difficult_button->move(650,500);
    history_button->move(650,700);

    connect(simple_button,&QPushButton::clicked,this,[=](){
        this->close();
        gamehome* gh=new gamehome;
        gh->setGeometry(this->geometry());
        gh->show();

    });
    connect(normal_button,&QPushButton::clicked,this,[=](){
        this->close();
        gamehome* gh=new gamehome;
        gh->setGeometry(this->geometry());
        gh->setSpeed(100);
        gh->show();

    });
    connect(difficult_button,&QPushButton::clicked,this,[=](){
        this->close();
        gamehome* gh=new gamehome;
        gh->setGeometry(this->geometry());
        gh->setSpeed(60);
        gh->show();

    });
    QMessageBox* mb=new QMessageBox(this);
    connect(history_button,&QPushButton::clicked,this,[=](){

        QFile file(":res/maxscore.text");
        file.open(QIODevice::ReadOnly);
        QString his_score=file.readAll();
        qDebug()<<his_score;
        mb->setBaseSize(QSize(250,250));
        mb->setWindowTitle("历史最高分数");
        mb->setText(his_score);
        mb->setStandardButtons(QMessageBox::Ok);
        mb->exec();
        file.close();
    });
}

void gameselect::paintEvent(QPaintEvent *event)
{
    QPainter* pa=new QPainter(this);
    pa->drawPixmap(0,0,this->width(),this->height(),QPixmap(":res/gameselectbackground.png"));

}
